Fix execution in silent mode#407
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #407 +/- ##
==========================================
+ Coverage 82.05% 82.65% +0.60%
==========================================
Files 21 21
Lines 858 859 +1
Branches 89 89
==========================================
+ Hits 704 710 +6
+ Misses 154 149 -5
🚀 New features to boost your workflow:
|
| auto cout_strbuf = std::cout.rdbuf(); | ||
| auto cerr_strbuf = std::cerr.rdbuf(); | ||
|
|
||
| std::unique_ptr<xnull> nullbuf; |
There was a problem hiding this comment.
warning: no header providing "std::unique_ptr" is directly included [misc-include-cleaner]
src/xinterpreter.cpp:21:
- #ifndef EMSCRIPTEN
+ #include <memory>
+ #ifndef EMSCRIPTEN| auto null = xnull(); | ||
| std::cout.rdbuf(&null); | ||
| std::cerr.rdbuf(&null); | ||
| nullbuf = std::make_unique<xnull>(); |
There was a problem hiding this comment.
warning: no header providing "std::make_unique" is directly included [misc-include-cleaner]
nullbuf = std::make_unique<xnull>();
^There was a problem hiding this comment.
I think we can always allocate xnull before checking for the config.silent property and redirect only if this is needed. That would avoid a dynamic allocation here. Also we could take the opportunity of fixing this issue to write a small RAII object to perform the redirection.
|
This comment is just to educate myself more than anything. What is a situation somebody would use |
Description
@JohanMabille and I were discussing that xeus-cpp might not be respecting how execution works in silent mode.
To confirm this I forced
config.silentas true from the xeus side. Probably the statementconfig.silent = truecan be added at the top of theexecute_request_implto verify this.In silent mode on upstream I see the kernel segfaults.

Problem
The temporary
xnullobject used whenconfig.silent = truewas destroyed at the end of the if-block, leavingstd::coutandstd::cerrwith dangling streambuf pointers. This caused signal 11 (segmentation fault) on any subsequent flush or write.Solution
Prevent segmentation fault in silent execution mode by managing the lifetime of the xnull stream buffer with a std::unique_ptr. Now works as expected
Type of change
Please tick all options which are relevant.